angular.module('liemallfodder')
  .factory('WechatApi', function (ApiManager) {
    var api = {};

    api.getSignPackage = function (success,failure) {
      var body = {
        name: "/WechatApi/getSignPackage",
        data: {}
      };

      get(ApiManager,body,success,failure);
    };


    //预览图片
    api.previewImage = function (signature,urls) {
      signature.jsApiList = ['previewImage'];
      wx.config(signature);

      wx.ready(function () {
        wx.previewImage({
          current: urls[0],
          urls: urls
        });
      });
    };

    api.registerShare = function (signature,content) {
      signature.jsApiList = ['onMenuShareAppMessage','onMenuShareTimeline','onMenuShareQQ','onMenuShareQZone'];
      wx.config(signature);
      wx.ready(function () {

        var obj = {
          title: content.title,
          desc: content.desc,
          link: content.url,
          imgUrl: content.image,
          success: function (res) {
            alert('分享成功');
          },
          fail: function (res) {
            alert(JSON.stringify(res));
          }
        };

        //分享到微信好友
        wx.onMenuShareAppMessage(obj);
        //分享到朋友圈
        wx.onMenuShareTimeline(obj);
        //分享到qq
        wx.onMenuShareQQ(obj);
        //分享到qq空间
        wx.onMenuShareQZone(obj);
        //分享到微博
        //wx.onMenuShareWeibo(obj);
      });
    };

    return api;
  });
